<?php
	// Load variables.
		
	$ContentArchive	=	md_RequestParam('contentarchive');
	$Username		=	md_RequestParam('username');		

	if ( !isset($ContentArchive) || $ContentArchive == "")
	{
		mis_SendFunctionDie('Error',array('The contentarchive requested was invalid or missing.'));
	}
	if ( md_IsValidProductName($ContentArchive) == false )
	{
		mis_SendFunctionDie('Error',array('The contentarchive requested could not be served because its name was not a valid contentarchive name.'));
	}
	
	// Check the database for any information on the product.		
	if (!file_exists('addons/masterserver/scripts/'.md_ProductNameToFileName($ContentArchive).'.mis'))
	{
		mis_SendFunctionDie('Error',array('The contentarchive requested ('.$ContentArchive.') is not supported by this content server at the moment. (No .mis script)'));
	}
	
	if ( $md_db )
	{
		// See if the user has registered the product
		
		$register_slot	=	md_sql("SELECT count(r.username) as Registered FROM ".md_GetDatabaseName('register')." r, ".md_GetDatabaseName('products')." p, ".md_GetDatabaseName('contentarchive')." arch, ".md_GetDatabaseName('contentarchive_rel')." rel WHERE r.username = '".md_SlashGlobalVar($Username)."' AND r.product = p.id AND rel.product = p.id AND arch.id = rel.archive AND arch.name = '".md_SlashGlobalVar($ContentArchive)."'");
		
		if ($md_sql_row[$register_slot]['Registered'] == 0)
		{
			mis_SendFunctionDie('Error',array('Username '.$Username.' hasn\'t registered '.$ContentArchive.' and thus it cannot be installed!'));
		}
		
		md_clearslot($register_slot);
	}
	else
	{
		// Todo: We need support for content servers without databases
	}
	
	echo	file_get_contents('addons/masterserver/scripts/'.md_ProductNameToFileName($ContentArchive).'.mis');
	
?>